package com.example.lib_data.bmob

class MusicManager private constructor() {
    private var mMusics = emptyList<Song>()

    companion object {
        val instance = MusicManager()
    }

    fun getMusics() = mMusics

    /**
     * 加载音乐数据
     */
    fun loadMusics(onStart: () -> Unit, callBack: (List<Song>) -> Unit) {
        BmobManager.getInstance().queryMusics(
            onStart = { onStart() },
            onEnd = { songs: List<Song>? ->
                songs?.let {
                    mMusics = it
                    callBack(it)
                    return@queryMusics
                }
                callBack(emptyList())
            }
        )
    }
}